/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.app.ad.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.annotation.rest.AnonymousGetMapping;
import me.zhengjie.modules.app.ad.domain.AduserTabsDetail;
import me.zhengjie.modules.app.ad.service.AduserTabsDetailService;
import me.zhengjie.modules.app.ad.service.dto.AduserTabsDetailQueryCriteria;
import me.zhengjie.utils.SecurityUtils;

import org.apache.catalina.security.SecurityUtil;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author HaojieLi
* @date 2021-03-21
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "广告商坑位广告信息管理")
@RequestMapping("/api/aduserTabsDetail")
public class AduserTabsDetailController {

    private final AduserTabsDetailService aduserTabsDetailService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('aduserTabsDetail:list')")
    public void download(HttpServletResponse response, AduserTabsDetailQueryCriteria criteria) throws IOException {
        aduserTabsDetailService.download(aduserTabsDetailService.queryAll(criteria), response);
    }

    @AnonymousGetMapping("findTest")
    @Log("findTest")
    @ApiOperation("findTest")
//    @PreAuthorize("@el.check('aduserTabsDetail:list,adInfo:list')")
    public ResponseEntity<Object> findTest(AduserTabsDetailQueryCriteria criteria, Pageable pageable){
    	Map<String,Object> resultMap = new HashMap<String,Object>();
    	resultMap.put("data1", aduserTabsDetailService.findTest2());
    	resultMap.put("data2", aduserTabsDetailService.findTest3());
        return new ResponseEntity<>(resultMap,HttpStatus.OK);
    }

    @GetMapping
    @Log("查询广告商坑位广告信息")
    @ApiOperation("查询广告商坑位广告信息")
    @PreAuthorize("@el.check('aduserTabsDetail:list,adInfo:list')")
    public ResponseEntity<Object> query(AduserTabsDetailQueryCriteria criteria, Pageable pageable){
    	criteria.setAdUserId(SecurityUtils.getCurrentUserId() + "");
        return new ResponseEntity<>(aduserTabsDetailService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增广告商坑位广告信息")
    @ApiOperation("新增广告商坑位广告信息")
    @PreAuthorize("@el.check('aduserTabsDetail:add,adInfo:list')")
    public ResponseEntity<Object> create(@Validated @RequestBody AduserTabsDetail resources){
    	resources.setAdUserId(SecurityUtils.getCurrentUserId() + "");
        return new ResponseEntity<>(aduserTabsDetailService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改广告商坑位广告信息")
    @ApiOperation("修改广告商坑位广告信息")
    @PreAuthorize("@el.check('aduserTabsDetail:edit,adInfo:list')")
    public ResponseEntity<Object> update(@Validated @RequestBody AduserTabsDetail resources){
        aduserTabsDetailService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除广告商坑位广告信息")
    @ApiOperation("删除广告商坑位广告信息")
    @PreAuthorize("@el.check('aduserTabsDetail:del,adInfo:list')")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody String[] ids) {
        aduserTabsDetailService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
    
    //更新广告商所拥有的酒店坑位资源
    public void updateHotelTabResource(AduserTabsDetail resources) {
    	
    	
    	//更新酒店选项卡资源左边的数据
    	if(!"".equals(resources.getLeftMv())) {
    		
    	}
    	
    	//更新酒店选项卡资源右边的数据
		if(!"".equals(resources.getRightPics())) {
    		
    	}

    	//更新酒店选项卡资源apk展示的数据
		if(!"".equals(resources.getApkParams())) {
    		
    	}
    }
}